package com.cenjiawen.common;

import com.jfinal.kit.JsonKit;
import com.jfinal.kit.StrKit;

import cn.hutool.core.util.ReUtil;
import cn.hutool.core.util.StrUtil;

public class ZYIndexController2 extends IndexController {
	private final String REPLACE_MARK = "＇";

	protected Integer getPageSize() {
		int pageSize = getParaToInt("pageSize", PAGE_SIZE);
		setAttr("pageSize", pageSize);
		return pageSize;
	}

	protected void setJsonItems(Object object) {
		String json = JsonKit.toJson(object);
		String str = ReUtil.escape(json);
		setAttr("items", str);
	}

	@Override
	public String getPara(String name, String defaultValue) {
		String str = super.getPara(name, defaultValue);
		if (str == null) {
			return str;
		}
		return str.replace("'", REPLACE_MARK);
	}

	@Override
	public String getPara(int index) {
		String str = super.getPara(index);
		if (str == null) {
			return str;
		}
		return str.replace("'", REPLACE_MARK);
	}

	@Override
	public String getPara(String name) {
		String str = super.getPara(name);
		if (str == null) {
			return str;
		}
		return trimString(str);
	}

	@Override
	public String getPara(int index, String defaultValue) {
		String str = super.getPara(index, defaultValue);
		if (str == null) {
			return str;
		}
		str = StrUtil.trim(str);
		return str.replace("'", REPLACE_MARK);
	}

	public String getParaRelaceN(String name) {
		String value = getPara(name, "");
		return trimStringN(value);
	}

	protected String trimStringN(String value) {
		if (StrKit.isBlank(value)) {
			return "";
		}
		value = StrUtil.trim(value);
		value = value.replace("\n", "<br/>");
		value = value.replace("\t", " ");
		value = value.replace("'", REPLACE_MARK);
		return value;
	}

	protected String trimString(String value) {
		if (StrKit.isBlank(value)) {
			return "";
		}
		value = StrUtil.trim(value);
		value = value.replace("\n", " ");
		value = value.replace("\t", " ");
		value = value.replace("'", REPLACE_MARK);
		return value;
	}

	public String getParaTrim(String name) {
		String value = getPara(name, "");
		return trimString(value);
	}

	protected final static Integer YES = 1;
}
